//
//  IMListTableViewCell.m
//  markmap
//
//  Created by 甘世清 on 2024/5/19.
//

#import "IMListTableViewCell.h"

@implementation IMListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)SQ_Style:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
   
    
    [self.contentView addSubview:self.avatarImageView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.messageLabel];
    [self.contentView addSubview:self.timeLabel];
    
   
    [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(14);
        make.size.mas_equalTo(52);
        make.centerY.equalTo(self.contentView);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.avatarImageView).offset(2);
            make.left.equalTo(self.contentView).offset(82);
    }];
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.avatarImageView.mas_bottom).offset(-2);
        make.left.equalTo(self.nameLabel);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.messageLabel.mas_right);
        make.height.mas_equalTo(20);
        make.centerY.equalTo(self.nameLabel);
    }];
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = SQHexColor(@"#FFFFFF", 0.2);
    [self.contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.right.equalTo(self.messageLabel.mas_right);
        make.height.mas_equalTo(0.2);
        make.bottom.equalTo(self.contentView.mas_bottom);
    }];
    
    [self.contentView addSubview:self.badgeBg];
    [self.badgeBg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(30);
            make.left.equalTo(self.avatarImageView.mas_right).offset(-15);
            make.top.equalTo(self.avatarImageView.mas_top).offset(-15);
    }];
    
}
- (void)setModel:(IMListModel *)model{
    _model = model;
    [self.avatarImageView.headerImage sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"logo")];
    self.nameLabel.text = model.name;
   
    self.timeLabel.text = [Manager SQ_getTimeString:model.time];
    if (model.noReadCount > 0) {
        self.badgeBg.hidden = NO;
    } else {
        self.badgeBg.hidden = YES;
    }
    self.badge.badgeText = [NSString stringWithFormat:@"%d",model.noReadCount];
    if (self.model.msgType ==0 || self.model.msgType == 10) {
        self.messageLabel.text =model.content;
    } else if (self.model.msgType ==1) {
        self.messageLabel.text = SQNSLocalString(@"[图片]");
    } else if (self.model.msgType ==2) {
        self.messageLabel.text = SQNSLocalString(@"[表情]");
    }else if (self.model.msgType ==3) {
        self.messageLabel.text = SQNSLocalString(@"[语音]");
    }else if (self.model.msgType ==4) {
        self.messageLabel.text = SQNSLocalString(@"[视频]");
    }else if (self.model.msgType ==5) {
        self.messageLabel.text = SQNSLocalString(@"[地理位置]");
    }else if (self.model.msgType ==7) {
        self.messageLabel.text = SQNSLocalString(@"[语音通话]");
    }else if (self.model.msgType ==8) {
        self.messageLabel.text = SQNSLocalString(@"[视频通话]");
    }else if (self.model.msgType ==9) {
        self.messageLabel.text = SQNSLocalString(@"[礼物]");
    }else{
        self.messageLabel.text = @"";
    }
}
-(void)SQ_headerView{
    PeopleDetailViewController * vc = [[PeopleDetailViewController alloc]init];
    vc.uid = self.model.peopleId;
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}

- (HeaderView *)avatarImageView{
    if (!_avatarImageView) {
        _avatarImageView = [[HeaderView alloc]init];
        _avatarImageView.clipsToBounds = YES;
        [_avatarImageView.btn addTarget:self action:@selector(SQ_headerView) forControlEvents:UIControlEventTouchUpInside];
        _avatarImageView.layer.cornerRadius = 4;
        _avatarImageView.layer.masksToBounds = YES;
        _avatarImageView.headerImage.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _avatarImageView;
}
- (UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc]init];
        _messageLabel.font = FONT_REGULAR(13);
        _messageLabel.textColor = SQColor(@"#AAAAAA");
        _messageLabel.backgroundColor = UIColor.clearColor;
        
     }
    return _messageLabel;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(16);
        _nameLabel.textColor = UIColor.whiteColor;
        _nameLabel.backgroundColor = UIColor.clearColor;
        
     }
    return _nameLabel;
}
- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = FONT_REGULAR(12);
        _timeLabel.textColor = SQColor(@"#AAAAAA");
        _timeLabel.backgroundColor = UIColor.clearColor;
     }
    return _timeLabel;
}
- (UIView *)badgeBg{
    if (!_badgeBg) {
        _badgeBg = [[UIView alloc]init];
        _badgeBg.backgroundColor = UIColor.clearColor;
        _badgeBg.userInteractionEnabled = NO;
    }
    return _badgeBg;
}
- (JSBadgeView *)badge{
    if (!_badge) {
        _badge = [[JSBadgeView alloc]initWithParentView:self.badgeBg alignment:JSBadgeViewAlignmentCenter];
        _badge .backgroundColor = SQColor(@"#FF3B30");
        _badge.badgePositionAdjustment = CGPointMake(0, 0);
        _badge.badgeTextFont = FONT_REGULAR(12);
        _badge.layer.cornerRadius = 8;
        _badge.layer.masksToBounds = YES;
    }
    return _badge;
}
@end
